package com.gdut.simple.data.entity;

import android.content.ContentValues;
import android.database.Cursor;

import java.text.SimpleDateFormat;

import rx.functions.Func1;

public class History {

    private int id;
    private String title;
    private String url;
    private String type;
    private String createdAt;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public static final class Table {

        public static final String TABLE_NAME = "history";

        public static final String ID = "_id";
        public static final String COLUMN_TITLE = "title";
        public static final String COLUMN_URL = "url";
        public static final String COLUMN_TYPE = "type";
        public static final String COLUMN_CREATED_AT = "createdAt";

        public static final String CREATE = "create table if not exists " + TABLE_NAME +
                "(" +
                ID + " integer not null primary key autoincrement," +
                COLUMN_TITLE + " char(255) not null," +
                COLUMN_URL + " char(255) not null," +
                COLUMN_TYPE + " char(255) not null," +
                COLUMN_CREATED_AT + " char(20) not null" +
                ")";

        public static ContentValues INSERT(History history) {
            ContentValues values = new ContentValues();
            values.put(COLUMN_TITLE, history.getTitle());
            values.put(COLUMN_URL, history.getUrl());
            values.put(COLUMN_TYPE, history.getType());
            values.put(COLUMN_CREATED_AT, history.getCreatedAt());
            return values;
        }

        public static Func1<Cursor, History> MAPPER = new Func1<Cursor, History>() {
            @Override
            public History call(Cursor cursor) {
                History history = new History();
                history.setId(cursor.getInt(cursor.getColumnIndexOrThrow(ID)));
                history.setTitle(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_TITLE)));
                history.setUrl(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_URL)));
                history.setType(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_TYPE)));
                history.setCreatedAt(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CREATED_AT)));
                return history;
            }
        };

    }

}
